<template>
    <div class="common-layout">
        <el-container>
            <el-header>
                <div class="block">
                    <el-avatar shape="circle" :size="50" :src="avator" />
                    <span>{{ username }}</span>
                    <el-dropdown>
                        <span class="el-dropdown-link">
                            Dropdown List
                            <el-icon class="el-icon--right">
                                <arrow-down />
                            </el-icon>
                        </span>
                        <template #dropdown>
                            <el-dropdown-menu>
                                <el-dropdown-item>Action 1</el-dropdown-item>
                                <el-dropdown-item @click="open">退出登录</el-dropdown-item>
                            </el-dropdown-menu>
                        </template>
                    </el-dropdown>
                </div>
            </el-header>
            <el-container>
                <el-aside width="200px">Aside</el-aside>
                <el-main>Main</el-main>
            </el-container>
        </el-container>
    </div>
</template>

<script setup>
import request from '@/request/request';
import router from '@/router';
import { ref } from 'vue';
let avator = ref('')
avator.value = localStorage.getItem('avator')
let username = ref('')
username.value = localStorage.getItem('username')
import { ElMessage, ElMessageBox } from 'element-plus'

const open = () => {
    ElMessageBox.confirm(
        'proxy will permanently delete the file. Continue?',
        'Warning',
        {
            confirmButtonText: 'OK',
            cancelButtonText: 'Cancel',
            type: 'warning',
        }
    )
        .then(() => {
            request.post('/quit').then(res => {
                console.log(res);
                if (res.data.code == 10000) {
                    ElMessage({
                        type: 'success',
                        message: 'Delete completed',
                    })
                    router.push('/login')
                    localStorage.clear()
                }
            })

        })
        .catch(() => {
            ElMessage({
                type: 'info',
                message: 'Delete canceled',
            })
        })
}
</script>

<style lang="scss" scoped></style>